<layout name='layout' />

<div class="admin-main">

	<blockquote class="layui-elem-quote">
		<?php $model=C("TABLE_MODEL"); ?>
		<volist name="model" id="vo">
		<eq name="vo.show" value="1">
		<a href="<{:U('Category/index',array('mid'=>$vo['id']))}>" class="layui-btn layui-btn-small <?php if($mid!=$vo['id']){echo 'layui-btn-primary';} ?>"><{$vo['name']}></a>
		</eq>
		</volist>
		<button class="layui-btn layui-btn-small layui-btn-danger" onclick="openModel('<{:U('Category/add',array('mid'=>$mid))}>','添加','80%','80%');">
			<i class="fa fa-plus"></i> 添加分类
		</button>
		<button class="layui-btn layui-btn-small" onclick="window.location.reload();">
			<i class="fa fa-refresh"></i> 刷新
		</button>
	</blockquote>

	<fieldset class="layui-elem-field">
		<legend>分类管理</legend>

		<div class="layui-field-box">
			<form id="ajaxForm" method="post" action="#">
			<table class="site-table table-hover">
				<thead>
					<tr>
						<th>ID</th>								
						<th>名称</th>
						<th>链接</th>
						<th>排序</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody><!--minus-->
					<volist name="list" id="vo">
					<tr <neq name="vo.fid" value="0">class="child-<{$vo['fid']}>"</neq>>
						<td><{$vo.id}></td>
						<td <{$vo.style}>><a href="javascript:;" data-oid="<{$vo['id']}>" class="fa fa-minus-square-o opened plus-btn"></a> <eq name="vo.fid" value="0"><strong><{$vo.name}></strong><else/><{$vo.name}></eq> - (管理员：<eq name="vo.user" value="">无<else/><{$vo.user}></eq>)</td>
						<td><{$vo.url}></td>
						<td><{$vo.sort}></td>
						<td>
							<a href="javascript:;" onclick="openModel('<{:U('Category/edit' , array('id'=>$vo['id']))}>','编辑','80%','80%');" class="layui-btn layui-btn-mini">编辑</a>
							<a href="javascript:;" onclick="openModel('<{:U('Category/add' , array('mid'=>$mid,'fid'=>$vo['id'],'path'=>$vo['path']))}>','编辑','80%','80%');" class="layui-btn layui-btn-mini">添加分类</a>
							<a href="javascript:void(0);" onclick="del(<{$vo.id}>)" class="layui-btn layui-btn-danger layui-btn-mini">删除</a>
						</td>
					</tr>
					</volist>				
				</tbody>
			</table>
			</form>
		</div>
	</fieldset>
</div>
<script>
$(function(){
	$(".plus-btn").click(function(){
		var oid=$(this).attr("data-oid");
		if($(this).hasClass("closed")){
			$(this).removeClass("closed fa-plus-square-o").addClass("fa-minus-square-o opened");
			$(".child-"+oid).show();
		}else{
			$(this).removeClass("fa-minus-square-o opened").addClass("closed fa-plus-square-o");
			$(".child-"+oid).hide();
		}
	});
})

function del(cate){
	l = parent.layer.confirm('删除后不可恢复，确定吗？', {
		btn: ['确定','取消'] //按钮
	}, function(){
		parent.layer.close(l);	
		load = parent.layer.load(0,{shade: [0.7, '#000000']});
		parent.layer.close(load);
		$.ajax({
			type : "GET",
			data : {'id' : cate},
			url :  "<{:U('Category/del')}>",
			dataType : "json",
			success : function(data) {
				layer.close(load);
				if (data.status==1) {
					parent.layer.msg(data.info);
					window.location.reload();
				}else{
					parent.layer.open({
						type:0, 
						icon:2,
						content:data.info
					});
				}
				
			}
		})
	}, function(){
		layer.close(l);		
	});
}
</script>
		
